package com.woniuxy.hrp.web.AdminController;

import com.woniuxy.hrp.Vo.DoctorAndTimeVo;
import com.woniuxy.hrp.entity.Application;
import com.woniuxy.hrp.entity.Doctor;
import com.woniuxy.hrp.entity.DoctorAndTime;
import com.woniuxy.hrp.service.DoctorAndTimeService;
import com.woniuxy.hrp.unityhandler.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: hrph
 * @InterfaceName DoctorAndTimeController
 * @description:医生值班中间表Controller
 * @author: WY
 **/
@Transactional
@RestController
@RequestMapping("/api/v1/admin/doctorandtime")
public class DoctorAndTimeController {

    @Autowired
    private DoctorAndTimeService doctorAndTimeService;

    //新增医生值班
    @PostMapping("/add")
    public ResponseEntity add(@RequestBody DoctorAndTimeVo doctorAndTimeVo){
        doctorAndTimeVo.getDoctorAndTime().setStatus("y");
        doctorAndTimeService.add(doctorAndTimeVo.getDoctorAndTime(),doctorAndTimeVo.getArrangeTime());
        return new ResponseEntity("200","OK",null);
    }

    //进入排班界面查询所有医生
    @GetMapping("/doctorlist")
    public ResponseEntity doctorlist(){
        List<Doctor> doctorList = doctorAndTimeService.findAllDoctor();
        return new ResponseEntity("200","OK",doctorList);
    }
    //根据医生id查询排班信息
    @GetMapping("/arrangelist")
    public ResponseEntity arrangelist(int id){
        List<DoctorAndTime> doctorAndTimes = doctorAndTimeService.findById(id);
        return new ResponseEntity("200","OK",doctorAndTimes);
    }

    //医生对排班的申请
    @PostMapping("/applyfor")
    public ResponseEntity Applyfor(@RequestBody Application application){
        doctorAndTimeService.applyfor(application);
        return ResponseEntity.SUCCESS;
    }

    //查询调班申请列表
    @GetMapping("/applyforlist")
    public ResponseEntity Applyforlist(){
        List<DoctorAndTime> doctorAndTimes = doctorAndTimeService.findApplyfor();
        return new ResponseEntity("200","Ok",doctorAndTimes);
    }

    //同意调班
    @PostMapping("/agree")
    public ResponseEntity agree(int id){
        doctorAndTimeService.agree(id);
        return ResponseEntity.SUCCESS;
    }

    //拒绝调班
    @PostMapping("/refuse")
    public ResponseEntity refuse(int id){
        doctorAndTimeService.refuse(id);
        return ResponseEntity.SUCCESS;
    }

    //修改前查询排班信息
    @GetMapping("/update")
    public ResponseEntity findById(int id){
        DoctorAndTime doctorAndTime = doctorAndTimeService.findByFid(id);
        return new ResponseEntity("200","OK",doctorAndTime);
    }
    //修改医生值班
    @PostMapping("/update")
    public ResponseEntity update(@RequestBody DoctorAndTimeVo doctorAndTimeVo){
        doctorAndTimeService.update(doctorAndTimeVo.getDoctorAndTime(),doctorAndTimeVo.getArrangeTime());
        return new ResponseEntity("200","OK",null);
    }

    //删除医生值班
    @PostMapping("/delete")
    public ResponseEntity delete(int id){
        doctorAndTimeService.delete(id);
        return new ResponseEntity("200","OK",null);
    }
}
